/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cinfo.siga.gestionacademica.datos.base;

/**
 *
 * @author lartkma
 */
public abstract class Transaccion {
    private Sesion sesion;

    public Transaccion(Sesion s){
        sesion = s;
    }
    
    protected <T> T obtener(Class<T> clase){
        return sesion.obtenerDAO(clase);
    }
    
    Sesion getSesion(){
        return sesion;
    }
    
    public abstract void accion();
    
    public static void realizar(Transaccion t){
        try{
            t.accion();
            t.getSesion().commit();
        }catch(Exception e){
            t.getSesion().rollback();
        }finally{
            t.getSesion().terminar();
        }
    }
    
}
